﻿{{include file="../00_include/01_head.tpl"}}
<script type="text/javascript">var base_url = "/", edialog, ndialog;</script>
<div class='l-h-28 g-d-w  b-r-t-4 p-l-20 b-d-b-c-ddd p-r'>
    <span>Home</span>
    <span class="arrow_space"></span>
    <span>Content</span>
    <span class="arrow_space"></span>
    <span>{{$type|default:''|ucwords}}</span>
    <div class="p-a t-8 r-8 l-h-16 z-i-100">
        <a class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p add-icon" href="/admincp/backend/content/editor?type={{$type|default:''}}">Add</a>
        <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p refresh-icon" onclick="menu.Refresh()">Refresh</span>
        <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p setting-icon" onclick="menu.Setting()">Setting</span>
        <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p menu-icon" onclick="accessdenied()">Menu</span>
    </div>
</div>
<div class="grid_12- p-a- t-0- l-0- b-0- b-g-c-w- z-i-1 ">
    <div id="gridview" class="frmjqxgrid p-r m-h-500">
        <div id="jqxGrid" style="border: none;"></div>
        {{if isset($type)}}<div class="d-p-b h-28 b-d-t-c-ddd"></div>{{/if}}
        <div class="p-a b-4 l-8 l-h-16 z-i-100 p-b-2">
            <a class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p add-icon" href="/admincp/backend/content/editor?type={{$type|default:''}}">Add</a>
            <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p refresh-icon" onclick="menu.Refresh()">Refresh</span>
            <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p setting-icon" onclick="menu.Setting()">Setting</span>
            <span class="l-h-16 p-l-20 p-r-8 f-l hover-50 c-s-p menu-icon" onclick="accessdenied()">Menu</span>
        </div>
    </div>
</div>
{{include file="../base/grid_setting.tpl"}}
<!--<div id="window">
    <div id="windowHeader" >
        <img class="f-l m-r-4" src="/libraries/images/16/fileview_text.png" alt="" />
        <span class="f-l l-h-16">
            Category
        </span>
    </div>
    <div style="overflow: hidden;" id="windowContent">
        <div class="p-r-2 h-i p-b-2 biz">
            Loading...
        </div>
    </div>
</div>-->
<div class="grid_12- d-p-n">
    <div id="editor_box" class="b-d-c-ccc- p-r b-g-c-w- p-4">
        <div class="grid_x biz"></div>
    </div>
</div>
<div class="clear"></div>
<script type="text/javascript">
    var menu=(function(){
        return{
            AddItem:function(){
                _detail('');
            },
            EditItem:function(id){
                _detail(id);
            },
            Save:function(){
                accessdenied();
            },
            Cancel:function(){
                $('#editor_box').dialog('close');
            },
            DeleteItem:function(id){
                accessdenied();
            },
            RestoreItem:function(){
                accessdenied();
            },
            PublicItem:function(){
                accessdenied();
            },
            PrivateItem:function(){
                accessdenied();
            },
            Setting:function(){
                bckdialog({
                    message:$('#window-sOpt'),
                    icon:"<img class='p-a t-7 l-8' src='/libraries/images/16/option.gif'/>",
                    title:'Setting'
                }).open();
            },
            Refresh:function(){
                $("#jqxGrid").jqxGrid('updatebounddata');
            }
        };
    }());

    
    function _detail(id){

        backendloading();
        $("#editor_box .biz").load(
        "/admincp/backend/content/editor/" + id+"?type={{$type|default:''}}",
            function() {
                bckdialog({
                    title:'Content',message:$('#editor_box')
                }).open();
//                islc({
//                    element:'#cate_parent',num:2,minwidth:'480px',height:'240px',
//                    multi:false,aclass:'_mul',style :{'margin-top':'-120px'},
//                    title:'Parent',filter:true
//                });
                $( "#tabs" ).tabs();
                backendloaded();
                addEditorContent('news_content',400);
                $("#news_frm").validationEngine();
            }
        );
    }
    function AliasTo(from,element){
        if($(from).val()==$(from+'_curent').val())return;
        var url="/admincp/backend/excution/getalias";
        var data={text:$(from).val()};
        var proc=new backend({
            url:url,data:data,
            callback:function(rsdata){
                if(rsdata.result===1){
                    $(element).val(rsdata.alias);
                    $(from+'_curent').val($(from).val());
                }else{
                    bckdialog().open(rsdata.message);
                }
            }
        }).call();
    }
    var grid_options,
        adatafiels  ={{$datafields|json_encode}},
        acolumns    ={{$columns|json_encode}},
        alistitems  ={{$list|json_encode}},
        jqxGrid;
    var bindingsource='{{$bindingsource}}';

    
    function handleEvents(){
        try{
            acolumns['_id'].cellsrenderer = function (row, column, value) {
                var str="<span style='margin: 4px; float: left;'>";
                if(value && value>0){
                    try{
                        //value = $.parseJSON(value);
                        str+="\
                            <a href=\"/admincp/backend/content/editor/"+value+"?type={{$type|default:''}}\" \
                            class='w-16 h-16 f-l m-r-4 c-s-p hover-50 edit-icon' title='Edit'></a>\
                        ";
                        str+="\
                            <div onclick=\"menu.DeleteItem('"+value+"');\" \
                            class='w-16 h-16 f-l m-r-4 c-s-p hover-50 del-icon' title='Delete'></div>\
                        ";

                    }catch(e){}
                }
                str+="</span>";
                return str;
            }
            acolumns['news_thumb'].cellsrenderer = function (row, datafield, value) {
                if(value==undefined || value=='')
                    return '<img style="margin-left: 2px;margin-top: 2px;" height="22" src="/libraries/images/16/batch-master/image.png"/>';
                else
                    return '<img style="margin-left: 2px;margin-top: 2px;" height="22" src="/data/thumbs/' + value + '"/>';
            }
//            acolumns['cate_position'].createeditor=function (row, cellvalue, editor) {
//                editor.jqxNumberInput({ decimalDigits: 0 });
//            };
//            acolumns['cate_position'].validation= function (cell, value) {
//                if (value < -99 || value > 99) {
//                    return { result: false, message: "Position should be in the -99 to 99 interval" };
//                }
//                return true;
//            };
//            acolumns['cate_title'].validation= function (cell, value) {
//                if (value =="") {
//                    return { result: false, message: "Title should be not empty." };
//                }
//                return true;
//            };
            $("#jqxGrid").bind('cellendedit', function (event) {
                try{
                    var args = event.args;
                    var column = args.datafield ,_row = args.rowindex,_value = args.value;
                    var _data=$("#jqxGrid").jqxGrid('getrowdata', _row);
                    var _id=_data._id;
                    if(_id==undefined || _id==""){
                        return;
                    }
                    switch(column){
                        case "cate_status":
                            if(_value=="true" || _value ==true) _value="true";
                            else _value="false";
                            backend_update('category','categories','cate',_id,{'cate_status':_value});
                            break;
                        case 'cate_position':
                            if(_value!=_data.cate_position)
                                backend_update('category','categories','cate',_id,{'cate_position':_value});
                            break;
                        case 'cate_title':
                            if(_value!=_data.cate_title)
                                backend_update('category','categories','cate',_id,{'cate_title':_value});
                            break;
                        default:
                        alert("Unkown this cell. Maybe 'editable' of this colums is 'off'."); 
                    }
                }catch(e){
                    alert(e.message);
                }
            });
        }catch(e){}
    }

    $(document).ready(function(){
        initSetting();
        Grid({
            grid_opt:{
                {{if not isset($type)}}pageable:true,pagesize:20,pagesizeoptions  :['20','50','100', '200', '500'],virtualmode: true,{{/if}}
                //groupable: true,groups: ['cate_parent']
                editable:true,editmode:'dblclick',
                selectionmode: 'singlecell'
            }
        }).init();
        
    });
</script>
<script src="/libraries/backend/backend.grid.default.js"></script>
{{include file="../00_include/02_foot.tpl"}}
